hrac2: je-li nacata: 90% bude pokracovat, 10% zkusi jinam
pri pokracovani muze najit podvod
neni-li nacata, zkusi jinam
potopi-li hrac2 lod a je-li to posl. moznost, pak na 50% podvod potopena,
pokud je to jen prubezny zasah (ne prvni), pak 5% zasah podvod
]]
function hrajlode(h)
local planek = room.planek
local pompole = {}
for p = 1, maxlodex * maxlodey do
pompole[p] = {}
end
local pocet
local divnych
local nacata, potopena
local cinnost
local vysl
local lod
local sx, sy
nacata = false
for i = 1, maxlodex do
for j = 1, maxlodey do
if planek[h][2][i][j] == 3 then
nacata = true
end
end
end
if h == 1 then
if nacata then
local rand100 = random(100)
if isRange(rand100, 0, 49) then
cinnost = 1
elseif isRange(rand100, 50, 69) then
cinnost = 2
else
cinnost = 3
end
else
local rand100 = random(100)
if isRange(rand100, 0, 69) then
cinnost = 2
else
cinnost = 3
end
end
elseif nacata then
local rand100 = random(100)
if isRange(rand100, 0, 89) then
cinnost = 1
else
cinnost = 2
end
else
cinnost = 2
end
pocet = 0
sx = -1
switch(cinnost){
[1] = function()
for i = 1, maxlodex do
for j = 1, maxlodey do
if planek[h][2][i][j] == 0 then
if i > 1 and planek[h][2][i - 1][j] == 3 or i < maxlodex and planek[h][2][i + 1][j] == 3 or j > 1 and planek[h][2][i][j - 1] == 3 or j < maxlodey and planek[h][2][i][j + 1] == 3 then
pocet = pocet + 1
pompole[pocet][1] = i
pompole[pocet][2] = j
end
end
end
end
if pocet == 0 then
for i = 1, maxlodex do
for j = 1, maxlodey do
if planek[h][2][i][j] == 6 then
pocet = pocet + 1
pompole[pocet][1] = i
pompole[pocet][2] = j
end
end
end
end
if pocet > 0 then
pocet = random(pocet) + 1
sx = pompole[pocet][1]
sy = pompole[pocet][2]
end
end,
[2] = function()
if h == 2 and random(100) < 75 then
for i = 2, maxlodex - 1 do
for j = 2, maxlodey - 1 do
if planek[h][2][i][j] == 0 then
pocet = pocet + 1
pompole[pocet][1] = i
pompole[pocet][2] = j
end
end
end
end
if pocet == 0 then
for i = 1, maxlodex do
for j = 1, maxlodey do
if planek[h][2][i][j] == 0 then
pocet = pocet + 1
pompole[pocet][1] = i
pompole[pocet][2] = j
end
end
end
end
if pocet > 0 then
pocet = random(pocet) + 1
sx = pompole[pocet][1]
sy = pompole[pocet][2]
end
end,
}
if sx == -1 then
sx = random(maxlodex) + 1
sy = random(maxlodey) + 1
end
lod = planek[3 - h][1][sx][sy]
if isRange(lod, 1, 3) then
posltrefena = 3 + random(2)
elseif isRange(lod, 4, 5) then
posltrefena = 0
elseif lod == 6 then
posltrefena = 1
elseif lod == 7 then
posltrefena = 2
else
posltrefena = -1
end
if planek[h][2][sx][sy] ~= 0 and planek[h][2][sx][sy] ~= 2 and h == 1 then
if lod == 0 then
vysl = 8
else
vysl = 9
end
elseif lod == 0 then
vysl = 1
planek[h][2][sx][sy] = 1
else
potopena = true
for i = 1, maxlodex do
for j = 1, maxlodey do
if i ~= sx or j ~= sy then
if planek[3 - h][1][i][j] == lod and planek[h][2][i][j] ~= 3 then
potopena = false
end
end
end
end
if potopena then
vysl = 4
else
vysl = 3
end
if planek[h][2][sx][sy] == 6 then
planek[h][2][sx][sy] = vysl
vysl = vysl + 3
else
planek[h][2][sx][sy] = vysl
end
if vysl == 4 and h == 2 then
pocet = 0
for i = 1, maxlodex do
for j = 1, maxlodey do
if i ~= sx and j ~= sy and planek[3 - h][1][i][j] == lod then
if i > 1 and (planek[h][2][i - 1][j] == 0 or planek[h][2][i - 1][j] == 6) or i < maxlodex and (planek[h][2][i + 1][j] == 0 or planek[h][2][i + 1][j] == 6) or j > 1 and (planek[h][2][i][j - 1] == 0 or planek[h][2][i][j - 1] == 6) or j < maxlodey and (planek[h][2][i][j + 1] == 0 or planek[h][2][i][j + 1] == 6) then
pocet = pocet + 1
end
end
end
end
if pocet == 0 then
vysl = 5
end
end
if vysl == 3 and h == 2 then
pocet = 0
for i = 1, maxlodex do
for j = 1, maxlodey do
if i ~= sx and j ~= sy and planek[3 - h][1][i][j] == lod then
if planek[h][2][i][j] == 3 then
pocet = pocet + 1
end
end
end
end
if pocet > 0 and random(100) < 10 then
vysl = 1
planek[h][2][sx][sy] = 6
end
end
if planek[h][2][sx][sy] == 4 then
for i = 1, maxlodex do
for j = 1, maxlodey do
if planek[3 - h][1][i][j] == lod then
planek[h][2][i][j] = 4
if i > 1 and planek[h][2][i - 1][j] == 0 then
planek[h][2][i - 1][j] = 2
end
if i < maxlodex and planek[h][2][i + 1][j] == 0 then
planek[h][2][i + 1][j] = 2
end
if j > 1 and planek[h][2][i][j - 1] == 0 then
planek[h][2][i][j - 1] = 2
end
if j < maxlodey and planek[h][2][i][j - 1] == 0 then